/**
 * 南昌市政府采购网
 *  
 */
import {Base,Item} from '../base';
//const iconv = require('iconv-lite');
class ncszfcg extends Base{
    document:Document;
    constructor(){
        super();
        this.name = "南昌市政府采购网";
        this.enabled = true;
        this.encode = "utf-8";
        this.debug = false;
        this.timeout = 1000000;
        this.collection = "ztb";
        this.collectionShowName = "招投标信息";
        this.keyField = "title";
    }
    getItems(pageIndex:number):Item[]{
        let num=pageIndex+1;
        let url=`http://www.ncszfcg.gov.cn/more2018.cfm?sid=100028001`;
        let result :Item[]= [];
        let content=this.spider.getSync(url);
        let $=this.cheerio.load(content);
        let that =this;
        $('.listbox li').each(function (index, ele) {
           try {
            let item =that.buildItem();
             item.title=$(ele).find('a').attr('title'); 
             (<any>item)['公告时间']= $(ele).find('div').text().trim()
              item.source=that.name;
              let uri='http://www.ncszfcg.gov.cn/'+$(ele).find('a').attr('href');
              (<any>item).url='http://www.ncszfcg.gov.cn/'+$(ele).find('a').attr('href');
              result=that.getExtraItem(uri,item,result);
           } catch (error) {
               console.log(error);
           }
        });
        return result;
    }
    getExtraItem(url:string, item:Item, result:Item[]) {
        let content = this.spider.getSync(url);
        let $ = this.cheerio.load(content,{decodeEntities: false});
        (<any>item).content =$('.container').html();
        result.push(item);
        return result;
    }
    getPageCount() {
        return 1;
    }
}
module.exports=new ncszfcg();